﻿#include "searchfrienditem.h"
#include "ui_searchfrienditem.h"
SearchFriendItem::SearchFriendItem(ServiceType type,const QString &text,QWidget *parent) :
    QWidget(parent),
    email(""),
    ui(new Ui::SearchFriendItem)
{
    ui->setupUi(this);
    ui->headImg_LB->setStyleSheet(QString("\
        #headImg_LB{\
            border-radius:25px;\
            border-image: url(:/background/imagesRes/%1.png) 0 0 0 0 stretch stretch;\
        }\
    ").arg(getServiceName(type)));
    ui->username->setText(text);
}

SearchFriendItem::SearchFriendItem(const QString &email,const QString &username,QWidget *parent) :
    QWidget(parent),
    email(email),
    ui(new Ui::SearchFriendItem)
{
    ui->setupUi(this);
    updateHeadImg();
    ui->username->setText(username);
}

SearchFriendItem::~SearchFriendItem()
{
    delete ui;
}
void SearchFriendItem::mousePressEvent(QMouseEvent* event){
    if(event->button()==Qt::LeftButton)
    {
        emit clicked(this);
        if(!email.isEmpty()){
            emit onClicked(email);
        }
    }
}
void SearchFriendItem::mouseDoubleClickEvent(QMouseEvent* event){
    if(event->button()==Qt::LeftButton){
        //emit showComm(email,ui->name_LB->text());
    }
}

void SearchFriendItem::updateHeadImg(){
    if(QFile::exists(QString("./accountData/Res/%1/headImg/head.png").arg(email))){
        ui->headImg_LB->setStyleSheet(QString("\
                border-radius:25px;\
                border-image: url(./accountData/Res/%1/headImg/head.png) 0 0 0 0 stretch stretch;\
        ").arg(email));
    }
}
void SearchFriendItem::setNormalStyle(){
    ui->SearchFriendItem_content->setStyleSheet(R"(
        #SearchFriendItem_content{
            background-color:rgb(228, 229, 230);
        }
        #SearchFriendItem_content:hover{
            background-color:rgb(214, 214, 215);
        }
    )");
}
void SearchFriendItem::setClickStyle(){
    ui->SearchFriendItem_content->setStyleSheet(R"(
        #SearchFriendItem_content{
            background-color:rgb(201, 200, 198);
        }
    )");
}

QString SearchFriendItem::getEmail(){
    return this->email;
}
